package top.weiliang.springboot3.entity.auth;

import com.baomidou.mybatisplus.annotation.*;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import top.weiliang.springboot3.volidate.CommonValidate;

import java.io.Serial;
import java.io.Serializable;
import java.util.Date;

@Data
//实体类对应的表名称
@TableName("tb_user")
public class TbUser implements Serializable {
    @Serial
    private static final long serialVersionUID = 1L;

    //自增主键
    @TableId(type = IdType.AUTO)
    private Integer id;

    @NotBlank(message = "登录名必须填写", groups = {CommonValidate.Add.class})
    @Length(min = 3, max = 16, message = "登录名长度在3到16之间", groups = {CommonValidate.Add.class})
    private String username;
    @NotBlank(message = "登录密码必须填写", groups = {CommonValidate.Add.class, CommonValidate.Edit.class})
    @Length(min = 6, max = 16, message = "登录密码长度在4到20之间", groups = {CommonValidate.Add.class, CommonValidate.Edit.class})
    private String password;
    @NotBlank(message = "姓名必须填写", groups = {CommonValidate.Add.class})
    private String nickname;
    private String salt;
    @TableField(insertStrategy = FieldStrategy.NEVER, updateStrategy = FieldStrategy.NEVER)
    private String deleted;
    private Integer role;
    @TableField(insertStrategy = FieldStrategy.NEVER, updateStrategy = FieldStrategy.NEVER)
    private Date created;

    public TbUser view() {
        TbUser user = new TbUser();
        user.setId(this.id);
        user.setUsername(this.username);
        user.setNickname(this.nickname);
        user.setRole(role);
        user.setCreated(created);
        return user;
    }

}
